GXX=g++
CXXFLAGS=-Werror -Wall -O2
OTHERS=-s -march=native

SRC= $(wildcard *.cpp)
OBJ= $(SRC:.cpp=.o)

LIBFLAGS=-lGL -lGLU -lglut -lGLEW -lm

EXEC=$(shell basename "`pwd`")

all : ${EXEC}

${EXEC}: ${OBJ}
	@echo "Linking ............. : ${EXEC}"
	@${GXX} -o ${EXEC} $^ ${LIBFLAGS} ${CXXFLAGS} ${OTHERS}

%.o : %.cpp
	@echo "Compiling ........... : $@"
	@${GXX} -c $< ${CXXFLAGS} ${OTHERS}

.PHONY: clean cleandoc raz doc

clean : 
	@echo "Deleting all *.o"
	@rm -rf *.o

cleandoc :
	@echo "Deleting documentation"
	@rm -rf latex html glapplication.pdf

raz : clean cleandoc
	@echo "Deleting '${EXEC}' runnable" 
	@rm -rf ${EXEC}

SOURCES = $(shell find . \( -name '*.hpp' -o -name '*.cpp' \) -print)

doc : $(SOURCES)
	@echo "Generating documentation"
	@doxygen > /dev/null
	@(cd latex && make > /dev/null)
	@(cd latex && mv refman.pdf ../glapplication.pdf)